

import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:sph_driver/Main/FindOil/OilDetails.dart';

import '../../AppConfig/Config.dart';
import '../../l10n/messages.dart';

class FindOil extends StatefulWidget {
  const FindOil({super.key});

  @override
  State<FindOil> createState() => _FindOilState();
}

class _FindOilState extends State<FindOil> {

  List<ItemEntity> sortList = [
    ItemEntity(
      key: "one_list_key",
      value: "0",
      name:"按距离最近",
    ),
    ItemEntity(
      key: "one_list_key",
      value: "1",
      name:"按价格最近",
    ),

  ];
  List<ItemEntity> oilList = [
    ItemEntity(
      key: "one_list_key",
      value: "0",
      name:"0#柴油",
    ),
    ItemEntity(
      key: "one_list_key",
      value: "1",
      name:"-10#柴油",
    ),
    ItemEntity(
      key: "one_list_key",
      value: "1",
      name:"-20#柴油",
    ),
    ItemEntity(
      key: "one_list_key",
      value: "1",
      name:"-35#柴油",
    ),
    ItemEntity(
      key: "one_list_key",
      value: "1",
      name:"LNG#天然气",
    ),

  ];
  List<ItemEntity> cityList = [
    ItemEntity(
      key: "one_list_key",
      value: "0",
      name:"全国",
    ),
    ItemEntity(
      key: "one_list_key",
      value: "1",
      name:"背景",
    ),
    ItemEntity(
      key: "one_list_key",
      value: "1",
      name:"苏州",
    ),
    ItemEntity(
      key: "one_list_key",
      value: "1",
      name:"河北",
    ),
    ItemEntity(
      key: "one_list_key",
      value: "1",
      name:"天津",
    ),

  ];
  int sortType =0;
  int oilType =0;
  int cityType =0;

  List oilTitle =["中石油苏州强胜路加油站","中石油苏州强胜路加油站","中石油苏州强胜路加油站","中石油苏州强胜路加油站"];

  FocusNode focusNode = FocusNode();
  BrnSearchTextController scontroller = BrnSearchTextController();
  TextEditingController textController = TextEditingController();
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    ///initState 中添加监听，记得销毁
    textController.addListener(() {
      if (focusNode.hasFocus) {
        if (!BrunoTools.isEmpty(textController.text)) {
          scontroller.isClearShow = true;
          scontroller.isActionShow = true;
        }
      }
    });
    focusNode.addListener(() {
      if (focusNode.hasFocus) {
        if (!BrunoTools.isEmpty(textController.text)) {
          scontroller.isClearShow = true;
        }
      }
    });
  }
  @override
  Widget build(BuildContext context) {
    var messages = AppLocalizations.of(context)!;
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(

        backgroundColor: Colors.white,
          title: Container(
            color: Colors.white,
            height: 40.h,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Container(
                  height: 40.h,
                  width: screenSize.width-100.w,

                  child:  BrnSearchText(
                    focusNode: focusNode,
                    controller: textController,
                    searchController: scontroller..isActionShow = false,
                    innerColor:MyColors.backgreyColor,
                    borderRadius:BorderRadius.all(const Radius.circular(30.0)),
                    hintText:"搜索加油站、加油地址",
                    onTextClear: () {
                      debugPrint('sss');
                      return false;
                    },
                    autoFocus: true,
                    onActionTap: () {
                      scontroller.isClearShow = false;
                      scontroller.isActionShow = false;
                      focusNode.unfocus();
                      BrnToast.show('取消', context);
                    },
                    onTextCommit: (text) {
                      BrnToast.show('提交内容 : $text', context);
                    },
                    onTextChange: (text) {
                      BrnToast.show('输入内容 : $text', context);
                    },
                  ),
                ),

                GestureDetector(
                  child: Image.asset("lib/Images/PersonCenter/搜索话筒icon.png",width: 15.w,height: 15.h,),
                  onTap: (){

                  },
                ),
              ],
            ),
          ),
      ),
      body: Column(
        children: [
          SizedBox(height: 5.h,),
          Container(
            color: Colors.white,
            height: 30.h,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Container(
                  width: 110.w,
                  height: 30.h,
                  child:  BrnSimpleSelection.radio(

                    menuName: "充值交易",
                    menuKey: "default",
                    themeData: BrnSelectionConfig(
                      menuNormalTextStyle:BrnTextStyle(color: Colors.black,fontSize: 14.sp),
                      menuSelectedTextStyle:BrnTextStyle(color: MyColors.themeColor,fontSize: 14.sp),
                      itemSelectedTextStyle:BrnTextStyle(color: MyColors.themeColor,fontSize: 14.sp),
                      itemNormalTextStyle:BrnTextStyle(color: Colors.black,fontSize: 14.sp),
                    ),
                    items:sortList,
                    onSimpleSelectionChanged: (
                        List<ItemEntity> filterParams) {
                      //BrnToast.show(filterParams.map((e) => e.value).toList().join(','), context);
                      setState(() {
                        filterParams.map((e) => e.value).toList().join(',')=="0"?
                        sortType=0:sortType=1;
                      });
                    },

                  ),
                ),
                Container(
                  width: 1.w,
                  height: 30.h,
                  color: MyColors.backgreyColor,
                ),
                Container(
                  width: 110.w,
                  height: 30.h,
                  child:  BrnSimpleSelection.radio(

                    menuName: "0#柴油",
                    menuKey: "default",
                    themeData: BrnSelectionConfig(
                      menuNormalTextStyle:BrnTextStyle(color: Colors.black,fontSize: 14.sp),
                      menuSelectedTextStyle:BrnTextStyle(color: MyColors.themeColor,fontSize: 14.sp),
                      itemSelectedTextStyle:BrnTextStyle(color: MyColors.themeColor,fontSize: 14.sp),
                      itemNormalTextStyle:BrnTextStyle(color: Colors.black,fontSize: 14.sp),
                    ),
                    items:oilList,
                    onSimpleSelectionChanged: (
                        List<ItemEntity> filterParams) {
                      //BrnToast.show(filterParams.map((e) => e.value).toList().join(','), context);
                      setState(() {
                        filterParams.map((e) => e.value).toList().join(',')=="0"?
                        sortType=0:sortType=1;
                      });
                    },

                  ),
                ),
                Container(
                  width: 1.w,
                  height: 30.h,
                  color: MyColors.backgreyColor,
                ),
                Container(
                  width: 110.w,
                  height: 30.h,
                  child:  BrnSimpleSelection.radio(

                    menuName: "城市",
                    menuKey: "default",
                    themeData: BrnSelectionConfig(
                      menuNormalTextStyle:BrnTextStyle(color: Colors.black,fontSize: 14.sp),
                      menuSelectedTextStyle:BrnTextStyle(color: MyColors.themeColor,fontSize: 14.sp),
                      itemSelectedTextStyle:BrnTextStyle(color: MyColors.themeColor,fontSize: 14.sp),
                      itemNormalTextStyle:BrnTextStyle(color: Colors.black,fontSize: 14.sp),
                    ),
                    items:cityList,
                    onSimpleSelectionChanged: (
                        List<ItemEntity> filterParams) {
                      //BrnToast.show(filterParams.map((e) => e.value).toList().join(','), context);
                      setState(() {
                        filterParams.map((e) => e.value).toList().join(',')=="0"?
                        sortType=0:sortType=1;
                      });
                    },

                  ),
                ),
              ],
            ),
          ),
          Container(
            height: oilTitle.length * 128.h,
            child:
            ListView.builder(
                shrinkWrap:false,
                itemCount: oilTitle.length,
                itemBuilder: (BuildContext context, int index) {
                  return GestureDetector(
                    child: Container(
                      margin: EdgeInsets.only(bottom: 8.h),
                      height: 128.h,
                      color: Colors.white,
                      child: Row(
                        children: [
                          Image.asset("lib/Images/PersonCenter/加油站示例图片.png",width: 128.w,height: 128.h,),
                          SizedBox(width: 8.w,),
                          Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(oilTitle[index],style: TextStyle(color: Colors.black),),
                              SizedBox(height: 8.h,),
                              Row(
                                children: [
                                  Text("¥"+"5.33",style: TextStyle(color: MyColors.themeColor,fontSize: 18.sp)),
                                  BrnTagCustom(
                                    tagText: "优惠"+"¥"+"0.20",
                                    backgroundColor: MyColors.themeColor,
                                  ),
                                ],
                              ),
                              SizedBox(height: 8.h,),
                              Row(
                                children: [
                                  Text("1.63"+"Km",style: TextStyle(color: Colors.black,fontSize: 13.sp),),
                                  Icon(Icons.near_me,color: Colors.blue,),
                                  Text("工业园区强胜路120号",style: TextStyle(color: Colors.black,fontSize: 13.sp),),
                                ],
                              ),

                              SizedBox(height: 8.h,),
                              Row(
                                children: [
                                  BrnTagCustom(
                                    tagText: "老张加油",
                                    backgroundColor: Colors.yellow,
                                    fontSize: 12.sp,
                                  ),
                                  SizedBox(width: 4.w,),
                                  BrnTagCustom.buildBorderTag(
                                    tagText: '认证通过',
                                    textColor: MyColors.themeColor,
                                    borderColor: MyColors.themeColor,
                                    borderWidth: 1,
                                    fontSize: 10.sp,
                                  ),
                                  SizedBox(width: 4.w,),
                                  BrnTagCustom.buildBorderTag(
                                    tagText: '高速出入口',
                                    textColor: MyColors.themeColor,
                                    borderColor: MyColors.themeColor,
                                    borderWidth: 1,
                                    fontSize: 10.sp,
                                  ),
                                ],
                              ),

                            ],
                          ),

                        ],
                      ),
                    ) ,
                    onTap: (){
                      Navigator.push(context,
                          MaterialPageRoute(builder: (context) {
                            return OilDetails(
                            );
                          }));
                    },
                  );


                }
            ),
          ),

       
        ],
      ),
    );
  }
}
